GBML manual / Backgrounds

background_look

Moves a background sideways by a different amount on every row of the screen, so a picture ripples like water, or a floor or a road runs away from you. bg is a background made with background_create, look is one of the BGLOOK_ constants, strength (1 to 3) is how strong it is, and speed is how fast it moves (what that means depends on the look). BGLOOK_NONE turns it off.

Works differently on Game Boy - The Game Boy moves the room's picture sideways line by line (ripple, sway, floor, road) with the Advance's shapes, and ends it when the room changes; a floor or a road needs a picture 256 pixels wide to go round. It cannot run together with blocks.

Works differently on Game Boy Color - The Game Boy Color moves the room's picture sideways line by line (ripple, sway, floor, road) with the Advance's shapes, and ends it when the room changes; a floor or a road needs a picture 256 pixels wide to go round.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

background_look(bg, look, strength, speed)

Arguments

NameType
bgbackground
lookbglook
strengthint
speedreal

Returns

Nothing.

Description

Moves a background sideways by a different amount on every row of the screen, so a picture ripples like water, sways like a dream, or a floor or a road runs away from you. It is the background's version of sprite_warp: the picture is not turned or scaled, only slid along its rows.

A real capture, two pictures of the same sea scene with seaweed and slanting shafts of light - the first straight, the second with every row slid sideways by its own amount, so the seaweed and the light shafts wobble like something seen through waterA real capture, two pictures of the same sea scene with seaweed and slanting shafts of light - the first straight, the second with every row slid sideways by its own amount, so the seaweed and the light shafts wobble like something seen through water
A real capture, two pictures of the same sea scene with seaweed and slanting shafts of light - the first straight, the second with every row slid sideways by its own amount, so the seaweed and the light shafts wobble like something seen through water

The page's first example, a little way in. Left: the sea as the picture is. Right: the same room with BGLOOK_WAVE asked for. Real pictures from a Game Boy Advance ROM.

You give it four things:

A real capture, 16 frames played in a loop - the sea scene keeps rippling, the waves running down the screen and bending the seaweed and the light shafts as they passA real capture, 16 frames played in a loop - the sea scene keeps rippling, the waves running down the screen and bending the seaweed and the light shafts as they pass
A real capture, 16 frames played in a loop - the sea scene keeps rippling, the waves running down the screen and bending the seaweed and the light shafts as they pass

The ripple playing, strength 3 and a speed of 0.5. This picture is an animated PNG: your browser plays it by itself. A viewer that cannot animate shows only the first frame.

Which look

LookWhat it isWhat speed is
BGLOOK_WAVEa ripple, like a reflection in waterhow many rows the ripples travel down the screen every frame
BGLOOK_SWAYone wide, lazy bend that sways the whole picturehow many rows the bend travels down the screen every frame
BGLOOK_FLOORa floor that runs away from you: the lower a row is, the faster it slideshow many pixels the bottom row slides every frame
BGLOOK_ROADa straight road that swings into a bend, more and more toward the bottomhow fast the road swings from side to side

A ripple and a sway belong to the rows of the screen, not to the picture, so a background that scrolls slides through them.

Call it once

You do not need to call it every frame. Call it once, when you have made the background, and the look keeps going by itself. Calling it again with the same look and strength only changes the speed. Calling it with a different look or strength swaps the look, and a floor or a road starts again from its beginning.

Turning it off, and destroying the background

background_look(backdrop, BGLOOK_NONE, 0, 0);

This gives the slot back straight away. The last two numbers are ignored, but they have to be there.

A background survives a room change (it is yours until you destroy it), and so does its look: the look ends when you turn it off or when the background is destroyed. Turn the look off first. The look keeps its own copy of the picture's place, so a background you destroy while its look is on is let go of at the next frame instead of at once. Calling background_look on a background that has already been destroyed stops a development build with a message that says so.

Always destroy it, do not hide it. There is no way to hide a look, on purpose: something hidden would look gone but would still be using up one of the console's few row-by-row slots, and then the next effect you ask for would not appear and nothing would tell you why.

What it costs

A look uses one of the 8 row-by-row effects the console has, for as long as it is on, and no matrix. A room change keeps two of the eight for itself, so there are six left for you, shared with everything else that works row by row: sprite_warp, sprite_distort, draw_sprite_ripple, draw_text_3d and a sky from screen_backdrop. You can see how many are in use on the debug screen: the line called H-BLANK.

A ripple and a sway are a table in the cartridge: a few thousand bytes for the looks you use. A floor and a road are worked out every frame the speed is not 0, from a shape in the cartridge, into 640 bytes of memory for each background. A game that calls background_look at all keeps about 3 KB of the console's big, slow memory (EWRAM) for the four backgrounds it can have, and none of the small, fast memory; a game that never calls it keeps none of this. Picking the look with a variable keeps the tables of all four looks. It costs the console's time too, though not much: measured on a real ROM, about 1 hundredth of a frame for a ripple that stands still, 3 hundredths while it moves, and 5 hundredths for a floor or a road, which work out their rows every frame.

When there is no room

Ask for more than there is and the game does not skip it. A development build stops with a message that says how many slots there are and names every look that is holding one, so you know which one to turn off. A release build, which has no way to stop and show a message, draws the background straight. It never half-works.

Example

backdrop = background_create(0, 0, ts_doc_dungeon);
background_look(backdrop, BGLOOK_WAVE, 2, 0.5);

A background that ripples, the waves running down the screen. Call it once, when you have made the background.

// In the Step event, once the background is in the variable ackdrop.
if (btn_pressed(BTN_A)) {
    background_look(backdrop, BGLOOK_FLOOR, 2, 1);
}

if (btn_pressed(BTN_B)) {
    background_look(backdrop, BGLOOK_NONE, 0, 0);
}

Pressing A makes the background slide like a floor. Pressing B turns the look off.

On the GBA

Costs ONE of the console’s 8 row-by-row (H-Blank) effects for as long as the look is on, and no matrix. A room change keeps two of the eight for itself, so six are left for you, shared with everything else that works row by row. A ripple or a sway is a table in the cartridge. A floor and a road are worked out every frame the speed is not 0, from a shape in the cartridge, into 640 bytes of memory for each background. A project that calls it at all keeps about 3 KB of the console’s big, slow memory (EWRAM) for the four backgrounds a game can have, and none of the small, fast memory; a project that never calls it keeps none of this. It works on a background made by background_create and no other. A background survives a room change, so its look does too: it ends when you turn it off or when the background is destroyed. Turn it off first: the look keeps its own copy of the picture, so a background you destroy while it is on is let go of at the next frame instead of at once. Turning it off with BGLOOK_NONE hands the slot back at once, but hiding something does not: destroy it, do not hide it. If there is no room for another one, a development build stops with a message that names every look holding a slot; a release build draws the background straight. The in-game debug overlay shows the count as H-BLANK.

See also: background_createbackground_destroydraw_backgroundsprite_warpscreen_backdrop